<template>
  <header class="header">
    <div class="header-content">
      <h1 class="page-title">
        {{ $route.path == '/hotspot' ? '实时热点排行榜' : '热点文案创作' }}
      </h1>
      
      <div class="header-actions">
        <!-- 时间显示 -->
        <div class="time-display">{{ currentTime }}</div>
        
        <!-- 图标按钮 -->
        <div class="icon-buttons">
          <button class="icon-btn">
            <img src="/消息通知.svg" width="20px" alt="消息通知">
          </button>
           <button class="icon-btn">
            <img src="/刷新.svg"  alt="热点刷新">
          </button>
        </div>
      </div>
    </div>
  </header>
</template>

<script setup>
import {useRoute} from 'vue-router'
import { ref, onMounted, onUnmounted } from 'vue';

const route=useRoute()
const currentTime = ref('');

// 更新时间函数
const updateTime = () => {
  const now = new Date();
  currentTime.value = now.toLocaleString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
    hour12: false
  }).replace(/\//g, '-');
};

let timer = null;

onMounted(() => {
  updateTime(); 
  timer = setInterval(updateTime, 1000); 
});

onUnmounted(() => {
  if (timer) {
    clearInterval(timer);
  }
});
</script>

<style scoped>
.header {
  background-color: #ffffff;
  border-bottom: 1px solid #f0f0f0;
  padding: 0 2rem;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 72px;
}

/* 标题样式 */
.page-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #333333; 
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

/* 时间显示 */
.time-display {
  font-size: 0.875rem;
  color: #666666;
}

.icon-buttons {
  display: flex;
  gap: 1rem;
}

/* 图标按钮 */
.icon-btn {
  background: none;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #666666; 
  cursor: pointer;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background-color: #f5f5f5; 
  color: #333333;
}

</style>